Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/chart.js

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/chart.js

TypeScript definitions for chart.js

  • 2.9.41
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @types/chart.js?

@types/chart.js provides TypeScript type definitions for the Chart.js library, which is a popular JavaScript library for creating various types of charts and graphs. These type definitions help developers use Chart.js in TypeScript projects by providing type safety and autocompletion features.

What are @types/chart.js's main functionalities?

Creating a Line Chart

This code sample demonstrates how to create a basic line chart using Chart.js with TypeScript. The type definitions provided by @types/chart.js ensure that the configuration object adheres to the expected structure.

const lineChartConfig: Chart.ChartConfiguration = {
  type: 'line',
  data: {
    labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
    datasets: [{
      label: 'My First dataset',
      backgroundColor: 'rgba(75,192,192,0.4)',
      borderColor: 'rgba(75,192,192,1)',
      data: [65, 59, 80, 81, 56, 55, 40]
    }]
  },
  options: {
    responsive: true
  }
};
const ctx = document.getElementById('myChart') as HTMLCanvasElement;
new Chart(ctx, lineChartConfig);

Creating a Bar Chart

This code sample demonstrates how to create a bar chart using Chart.js with TypeScript. The type definitions ensure that the configuration object is correctly structured and provide autocompletion for the properties.

const barChartConfig: Chart.ChartConfiguration = {
  type: 'bar',
  data: {
    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
      ],
      borderColor: [
        'rgba(255, 99, 132, 1)',
        'rgba(54, 162, 235, 1)',
        'rgba(255, 206, 86, 1)',
        'rgba(75, 192, 192, 1)',
        'rgba(153, 102, 255, 1)',
        'rgba(255, 159, 64, 1)'
      ],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      yAxes: [{
        ticks: {
          beginAtZero: true
        }
      }]
    }
  }
};
const ctx = document.getElementById('myChart') as HTMLCanvasElement;
new Chart(ctx, barChartConfig);

Creating a Pie Chart

This code sample demonstrates how to create a pie chart using Chart.js with TypeScript. The type definitions help ensure that the configuration object is correctly structured and provide autocompletion for the properties.

const pieChartConfig: Chart.ChartConfiguration = {
  type: 'pie',
  data: {
    labels: ['Red', 'Blue', 'Yellow'],
    datasets: [{
      data: [300, 50, 100],
      backgroundColor: [
        '#FF6384',
        '#36A2EB',
        '#FFCE56'
      ],
      hoverBackgroundColor: [
        '#FF6384',
        '#36A2EB',
        '#FFCE56'
      ]
    }]
  },
  options: {
    responsive: true
  }
};
const ctx = document.getElementById('myChart') as HTMLCanvasElement;
new Chart(ctx, pieChartConfig);

Other packages similar to @types/chart.js

FAQs

Package last updated on 20 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc